package com.Servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jdbc.Jdbc;

/**
 * Servlet implementation class role_management_permissions
 */
@WebServlet("/role_management_permissions")
public class role_management_permissions extends HttpServlet {
	private static final long serialVersionusername = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public role_management_permissions() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String change = "";
		String change1 = "";
		String username = request.getParameter("username");
		String identity = request.getParameter("identity");
		String desc = request.getParameter("desc");
		change = "update authority set  role='" + identity + "' where username='" + username + "'";
		change1 = "update user set  role='" + identity + "' where username='" + username + "'";
		Jdbc j = null;
		Jdbc j1 = null;
		try {
			j = new Jdbc(change);
			j1 = new Jdbc(change1);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String change2 = "update authority set remarks='" + desc + "' where username = '" + username + "'";
		Jdbc j2 = null;
		try {
			j2 = new Jdbc(change2);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		request.getRequestDispatcher("showsuccess.jsp").forward(request, response);
	}

}
